package controllers

import (
	"github.com/astaxie/beego"
)

type RootController struct {
	beego.Controller
}

type MainController struct {
	RootController
}

func (this *MainController) Get() {
	this.CheckSession()

	//this.Ctx.Request.ParseForm()
	this.Data["fullname"] = this.GSession("fullname")
	this.Data["m1"] = "selected"
	this.Data["m2"] = "arrow"
	this.Data["m3"] = "arrow"
	this.Data["m4"] = "arrow"
	this.Data["m11"] = "start active"
	this.Layout = "layout.html"
	this.TplNames = "index.html"

}

func (this *RootController) CheckSession() interface{} {
	sess := this.StartSession()
	if sess.Get("username") == nil {
		this.Ctx.Redirect(302, "/login")
	}

	return sess.Get("username")
}

func (this *RootController) GSession(sessionName string) interface{} {
	sess := this.StartSession()
	if sess.Get("username") == nil {
		return nil
	}

	return sess.Get(sessionName)
}
